package com.item.controller;


import com.item.entities.CommonResult;
import com.item.entities.User;
import com.item.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

@RestController(value = "/user")
@Slf4j
public class UserController {

    @Resource
    private UserService userService;

    @Value("${server.port}")
    private String serverPort;


    @PostMapping(value = "/create")
    public CommonResult create(@RequestBody User user){

        int result = userService.create(user);
        if(result > 0)
        {
            return new CommonResult(200,"插入数据库成功,serverPort: "+serverPort,result);
        }else{
            return new CommonResult(444,"插入数据库失败",null);
        }
    }

    @PostMapping(value = "/{id}")
    public CommonResult<User> getUserById(@PathVariable(value = "id") Integer id){

        return new CommonResult<User>(200,"ok",userService.getUserById(id));
    }
}
